Modeling with uncertainty: A Bayesian parameter estimation tutorial

Introduction

Technical objective

Learn the basics of Bayesian parameter estimation and how it differs from frequentist parameter estimation

Substantive research question

How do emotion regulation strategies moderate the association between sleep and negative emotions?

Introductory remarks

In this tutorial, we will be applying the Bayesian lens to the estimation of parameters in a multilevel linear model. In particular, we will examine two emotion regulation strategies, cognitive reappraisal and expressive suppression, and whether they moderate the association between hours of sleep at night and negative affect the following day.

Briefly, in cognitive reappraisal, one changes the way in which they think about an emotionally-inducing event in order to alter their emotional response to that event. For example, instead of thinking about an exam as a difficult and consequential test of their abilities, a student might choose to frame the exam as an opportunity to show what they have learned. In expressive suppression, one regulates their emotions by inhibiting their external displays of emotion. For example, a student who feels nervous about an upcoming exam may stop themselves from showing a worried look on their face and telling their friends that they feel nervous. More information on these two emotion regulation strategies can be found in Gross & John (2003).

In our analysis, we will be looking at the relationships among these emotion regulation strategies, sleep, and negative affect (emotion). An individual’s emotion regulation and coping strategies are thought to moderate the impact of stress on sleep quality (Kahn et al., 2013). We might also be interested in whether emotion regulation strategies moderate the impact of sleep on negative emotions the following day. In other words, does a particular emotion regulation strategy help me manage my negative emotions after a night of poor sleep?

While we may not be able to precisely pin down the causal structure of the interactions between emotion regulation, sleep, and negative affect, we can run a regression analysis to get some preliminary insights. Our data come from the AMIB study, a multiple time-scale study of college students (Ram et al., 2012). In particular, we will be looking at students’ daily self-reports of their sleep and negative affect over the course of eight days, as well as their dispositional reappraisal and suppression scores. The data can be downloaded from https://thechangelab.stanford.edu/collaborations/the-amib-data/.

TODO: add section headers throughout (using # and ##, etc.) so that they show up under robobook ToC TODO: add commentary throughout to guide reader through the steps of the tutorial TODO: use this link for some example plots/analysis of Bayesian MLMs: https://www.rensvandeschoot.com/tutorials/brms-started/

Preliminaries

We begin by loading in the data from the online repository.

# set filepath for data file
filepath <- "https://raw.githubusercontent.com/LRI-2/Data/main/ILD/AMIBshare_persons_2019_0501.csv"
# read in the .csv file using the url() function
AMIB_persons <- read.csv(file=url(filepath),header=TRUE)
# set filepath for data file
filepath <- "https://raw.githubusercontent.com/LRI-2/Data/main/ILD/AMIBshare_daily_2019_0501.csv"
# read in the .csv file using the url() function
AMIB_daily <- read.csv(file=url(filepath),header=TRUE)

Data manipulation

We merge the daily-level variables (participant ID, day, hours of sleep, and negative affect) with the person-level variables (participant ID, reappraisal score, suppression score) into a single dataset.

# subset to day-level variables of interest
bpe_daily <- AMIB_daily[,c("id", "day", "slphrs", "negaff")]
# subset to person-level variables of interest
bpe_persons <- AMIB_persons[,c("id", "erq_reap", "erq_supp")]
# merge day- and person-level data
bpe_data <- merge(bpe_daily, bpe_persons, by = "id")

We center the emotion regulation questionnaire scores to facilitate the interpretation of model results.

# center the erq subscale score variables for interpretability
bpe_data$erq_reap_c <- scale(bpe_data$erq_reap, center=TRUE,scale=FALSE)[,1]
bpe_data$erq_supp_c <- scale(bpe_data$erq_supp, center=TRUE,scale=FALSE)[,1]

Initial data plotting

Before running our models, it can be helpful to examine the raw data.

# calculate correlations
cor(bpe_data[ ,c(-1, -5, -6)], use = "complete.obs") # dropping the id and non-centered erq columns
##                     day        slphrs       negaff   erq_reap_c    erq_supp_c
## day         1.000000000 -0.0480824055 -0.141990043  0.007004748 -0.0210526130
## slphrs     -0.048082405  1.0000000000 -0.155243242  0.001261147 -0.0004183473
## negaff     -0.141990043 -0.1552432419  1.000000000 -0.002317911  0.0246226777
## erq_reap_c  0.007004748  0.0012611469 -0.002317911  1.000000000 -0.1337777409
## erq_supp_c -0.021052613 -0.0004183473  0.024622678 -0.133777741  1.0000000000
# plot correlations
pairs.panels(bpe_data[ ,c(-1, -5, -6)])

We see relatively weak correlations overall, but note a weak negative correlation between hours of sleep and level of negative affect (-0.16), as well as a weak negative correlation between cognitive reappraisal and expressive suppression (-0.13). We also observe a weak negative correlation between day in study and level of negative affect (-0.14).

#TODO: plot the raw data to get a sense for any trends in the data
      # person-by-person & prototypical plot of negaff vs. sleep, w/ points color coded by higher reap (pink) vs. higher supp (blue)

Cognitive reappraisal model

TODO: add model equation in Latex

bpe.reap <- brm(negaff ~ 1 + day + slphrs + erq_reap_c + slphrs:erq_reap_c + (1 + slphrs + erq_reap_c|id), data = bpe_data, family = gaussian(),
  iter = 2000, chains = 4, cores = 4)
## Warning: Rows containing NAs were excluded from the model.
## Compiling Stan program...
## Start sampling
## Warning: There were 3 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
summary(bpe.reap)
## Warning: There were 3 divergent transitions after warmup. Increasing
## adapt_delta above 0.8 may help. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: negaff ~ 1 + day + slphrs + erq_reap_c + slphrs:erq_reap_c + (1 + slphrs + erq_reap_c | id) 
##    Data: bpe_data (Number of observations: 1421) 
##   Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup draws = 4000
## 
## Group-Level Effects: 
## ~id (Number of levels: 190) 
##                           Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## sd(Intercept)                 0.97      0.13     0.73     1.22 1.00     1480
## sd(slphrs)                    0.09      0.02     0.06     0.14 1.01      514
## sd(erq_reap_c)                0.08      0.07     0.00     0.24 1.00      664
## cor(Intercept,slphrs)        -0.75      0.09    -0.87    -0.54 1.00     2057
## cor(Intercept,erq_reap_c)     0.04      0.46    -0.84     0.84 1.00     2178
## cor(slphrs,erq_reap_c)       -0.13      0.51    -0.93     0.86 1.00     1843
##                           Tail_ESS
## sd(Intercept)                 2164
## sd(slphrs)                    1014
## sd(erq_reap_c)                1210
## cor(Intercept,slphrs)         2595
## cor(Intercept,erq_reap_c)     2506
## cor(slphrs,erq_reap_c)        2394
## 
## Population-Level Effects: 
##                   Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept             3.25      0.13     2.98     3.51 1.00     4201     3388
## day                  -0.07      0.01    -0.08    -0.05 1.00     8831     2544
## slphrs               -0.08      0.02    -0.11    -0.05 1.00     4345     3414
## erq_reap_c           -0.01      0.12    -0.24     0.23 1.00     3665     3019
## slphrs:erq_reap_c     0.00      0.01    -0.03     0.03 1.00     3770     3013
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.78      0.02     0.75     0.81 1.00     3186     3086
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
bayes_R2(bpe.reap)
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.4448962 0.01806424 0.4081658 0.4789125
plot(bpe.reap)

TODO: interpret model results (including Bayesian significance testing) TODO: make a visualization of this model that shows the prototypical individual and all individuals

Expressive suppression model

TODO: add model equation in Latex

bpe.supp <- brm(negaff ~ 1 + day + slphrs + erq_supp_c + slphrs:erq_supp_c + (1 + slphrs + erq_supp_c|id), data = bpe_data, family = gaussian(),
  iter = 2000, chains = 4, cores = 4)
## Warning: Rows containing NAs were excluded from the model.
## Compiling Stan program...
## Start sampling
## Warning: There were 2 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
summary(bpe.supp)
## Warning: There were 2 divergent transitions after warmup. Increasing
## adapt_delta above 0.8 may help. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: negaff ~ 1 + day + slphrs + erq_supp_c + slphrs:erq_supp_c + (1 + slphrs + erq_supp_c | id) 
##    Data: bpe_data (Number of observations: 1421) 
##   Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup draws = 4000
## 
## Group-Level Effects: 
## ~id (Number of levels: 190) 
##                           Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## sd(Intercept)                 0.94      0.13     0.67     1.21 1.01      618
## sd(slphrs)                    0.09      0.02     0.05     0.13 1.01      253
## sd(erq_supp_c)                0.11      0.07     0.01     0.26 1.01      474
## cor(Intercept,slphrs)        -0.73      0.12    -0.87    -0.44 1.01     1103
## cor(Intercept,erq_supp_c)     0.37      0.39    -0.53     0.93 1.00     1480
## cor(slphrs,erq_supp_c)       -0.18      0.46    -0.89     0.74 1.00     1269
##                           Tail_ESS
## sd(Intercept)                  818
## sd(slphrs)                     257
## sd(erq_supp_c)                 858
## cor(Intercept,slphrs)          699
## cor(Intercept,erq_supp_c)     2010
## cor(slphrs,erq_supp_c)        2162
## 
## Population-Level Effects: 
##                   Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept             3.23      0.13     2.97     3.49 1.00     4591     3115
## day                  -0.07      0.01    -0.08    -0.05 1.00     8736     2642
## slphrs               -0.08      0.02    -0.11    -0.05 1.00     4933     3276
## erq_supp_c            0.09      0.10    -0.11     0.28 1.00     2511     2261
## slphrs:erq_supp_c    -0.01      0.01    -0.03     0.02 1.00     3037     2803
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.78      0.02     0.75     0.81 1.00     2726     2863
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
bayes_R2(bpe.supp)
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.4440717 0.01846857 0.4080326 0.4794491
plot(bpe.supp)

TODO: interpret model results (including Bayesian significance testing) TODO: make a visualization of this model that shows the prototypical individual and all individuals

TODO: compare the two models (reap vs. supp - which one seems more predictive of better control of negaff?)

TODO: write up a final analysis/conclusion for this tutorial

Conclusion

[TODO]

References

Gross, J. J., & John, O. P. (2003). Individual differences in two emotion regulation processes: Implications for affect, relationships, and well-being. Journal of Personality and Social Psychology, 85(2), 348–362. https://doi.org/10.1037/0022-3514.85.2.348

Kahn, M., Sheppes, G., & Sadeh, A. (2013). Sleep and emotions: Bidirectional links and underlying mechanisms. International Journal of Psychophysiology, 89(2), 218–228. https://doi.org/10.1016/j.ijpsycho.2013.05.010

Ram, N., Conroy, D. E., Pincus, A. L., Hyde, A. L., & Molloy, L. E. (2012). Tethering theory to method: Using measures of intraindividual variability to operationalize individuals’ dynamic characteristics. In G. Hancock & J. Harring (Eds.), Advances in longitudinal methods in the social and behavioral sciences (pp. 81-110). New York: Information Age.